package com.group6.exam.teacher.service;

import java.util.List;
import java.util.Map;

import com.group6.exam.common.entity.PageModel;
import com.group6.exam.common.entity.UserInfoEntity;
import com.group6.exam.student.entity.StudentEntity;
import com.group6.exam.teacher.dao.ITeacherDao;
import com.group6.exam.teacher.dao.TeacherDaoImpl;

public class TeacherServiceImpl implements ITeacherService {

	private ITeacherDao teacherDao = new TeacherDaoImpl();

	@Override
	public boolean login(UserInfoEntity user) {
		return teacherDao.login(user);
	}

	@Override
	public List<Map<String, Object>> getMainMenus(String username) {
		return teacherDao.getMainMenus(username);
	}

	@Override
	public List<Map<String, Object>> getChildMenus(String username) {
		return teacherDao.getChildMenus(username);
	}

	/**
	 * 学生信息分页方法 
	 */
	public PageModel getStudentPageByPageModel(PageModel pageModel, String gradeName) {
		// 设置返回的PageModel所需的参数
		int totalRecords = teacherDao.getTotalRecords(gradeName);
		int pageSize = pageModel.getPageSize();
		
		PageModel page = new PageModel(totalRecords, pageSize);
		
		page.setCurrentPage(pageModel.getCurrentPage());
		page.setList(teacherDao.getStudentPage(pageModel, gradeName));
		return page;
	}

	/**
	 * 删除学生
	 */
	public int delete(int studentId) {
		return teacherDao.delete(studentId);
	}

	/**
	 * 添加学生
	 */
	public int addStudent(StudentEntity student) {
		return teacherDao.addStudent(student);
	}

	/**
	 * 查询班级
	 */
	public List<Map<String, Object>> selectGrade() {
		return teacherDao.selectGrade();
	}

	/**
	 * 通过Id查询学生信息
	 */
	public Map<String, Object> selectStudentById(int studentId) {
		return teacherDao.selectStudentById(studentId);
	}

	/**
	 * 修改学生信息
	 */
	public int update(StudentEntity student) {
		return teacherDao.update(student);
	}
}
